package com.wbp.cms.core.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;


/**
 * @Description: 
 * @Department:
 * @author andy.lhc
 * @date 2016年3月24日 下午1:01:05 
 */
public class CommonProperties {
  private Logger logger = Logger.getLogger(CommonProperties.class);
  
  private static CommonProperties instance = new CommonProperties();
  
  private Properties props = null;
  
  private CommonProperties()
  {
      props = new Properties();
      init();
  }
  
  private void init()
  {
      
      InputStream in = CommonProperties.class.getClassLoader().getResourceAsStream("config.properties");
      try
      {
          if (props == null)
              props = new Properties();
          
          props.load(in);
          
      }
      catch (IOException e)
      {
          logger.error("IOException", e);
      }
      finally
      {
          try
          {
              in.close();
          }
          catch (IOException e)
          {
              logger.error("IOException", e);
          }
      }
  }
  
  public static CommonProperties getInstance()
  {
      return instance;
  }
  
  public String getProperties(String key)
  {
      if (props == null)
          init();
      
      Object value = props.get(key);
      if (value == null)
          return null;
      return value.toString();
  }
}
